class_name PlayerInBattleState
extends BasicCharacterState

@export var point: int = 3
@export var anger_max: int = 100
@export var anger: int = 0:
	set = set_anger
@export var prop_id_array: Array[PropBar.PROP_TYPE]
#圣物
var prop_array: Array[Prop]
var cant_draw_card = 0:
	set = set_cant_draw_card
var anger_addition = 0:
	set = set_anger_addition
var next_point = 0:
	set = set_next_point
	
func take_damage(damage: int) -> void:
	super.take_damage(damage)
	calcute_anger(damage)


func calcute_anger(value: int) -> void:
	var t = clampi(floori(value * 0.5), 1, 999)
	anger = clampi(anger + t, 0, anger_max)
	state_changed.emit()
	
func set_next_point(value):
	next_point = value
	state_changed.emit(StateBar.STATE.NEXT_POINT, next_point)

func set_anger(value):
	anger = clampi(value, 0, anger_max)
	state_changed.emit()

func set_cant_draw_card(value):
	cant_draw_card = value
	state_changed.emit(StateBar.STATE.CANT_DRAW_CARD, cant_draw_card)


func set_anger_addition(value):
	anger_addition = value
	if anger_addition >= 0:
		state_changed.emit(StateBar.STATE.ANGER_ADDITION, anger_addition)
		Events.card_pool_info_update.emit()
		Events.card_table_card_info_update.emit()
			
func set_power(value: int) -> void:
	super.set_power(value)
	Events.card_pool_info_update.emit()
	Events.card_table_card_info_update.emit()

func set_shield(value: int) -> void:
	shield = clampi(value, 0, 999)
	CardManager.round_data.shield += shield
	state_changed.emit(StateBar.STATE.SHIELD, shield)
	
func set_weak(value: int) -> void:
	super.set_weak(value)
	Events.card_pool_info_update.emit()
	Events.card_table_card_info_update.emit()

func set_armor_break(value: int) -> void:
	armor_break = clampi(value, 0, 999)
	state_changed.emit(StateBar.STATE.ARMOR_BREAK, armor_break, armor_break)
	if Globals.monster_handler != null:
		for m in Globals.monster_handler.get_children():
			m.state.update_intent_signal.emit()
